vim9script noclear

if exists("g:did_load_filetypes")
	finish
endif
g:did_load_filetypes = 1

augroup filetypedetect
au BufNewFile,BufRead *.asm,*.[sS]	setf asm
au BufNewFile,BufRead *.c			setf c
au BufNewFile,BufRead *.cxx,*.c++,*.hh,*.hxx,*.hpp,*.ipp,*.moc,*.tcc,*.inl,*.C,*.H setf cpp
au BufNewFile,BufRead *.h			call dist#ft#FTheader()

au BufNewFile,BufRead *.py,*.pyw	setf python
au BufNewFile,BufRead .shrc,.bashrc,bashrc,bash.bashrc,.bash[_-]profile,.bash[_-]logout,.bash[_-]aliases,.bash[_-]history,*.bash setf bash
au BufNewFile,BufRead [mM]akefile.am,GNUmakefile.am	setf automake
au BufNewFile,BufRead CMakeLists.txt,*.cmake,*.cmake.in		setf cmake
au BufNewFile,BufRead configure.in,configure.ac setf config
au BufNewFile,BufRead *.diff,*.rej,*.patch		setf diff
au BufNewFile,BufRead *.dot,*.gv		setf dot
au BufNewFile,BufRead *.dts,*.dtsi,*.dtso,*.its,*.keymap	setf dts
au BufNewFile,BufRead COMMIT_EDITMSG,MERGE_MSG,TAG_EDITMSG,NOTES_EDITMSG,EDIT_DESCRIPTION	setf gitcommit
au BufNewFile,BufRead *[mM]akefile*,*.mk,*.mak,*.dsp,Kbuild setf make
au BufNewFile,BufRead {.,}tmux*.conf*		setf tmux
au BufNewFile,BufRead Kconfig.*,Config.in.*	setf kconfig
au BufNewFile,BufRead $VIMRUNTIME/doc/*.txt	setf help
au BufNewFile,BufRead *.txt
	\  if getline('$') !~ 'vim:.*ft=help'
	\|   setf text
	\| endif

runtime! ftdetect/*.vim
augroup END

au filetypedetect BufNewFile,BufRead,StdinReadPost *
	\ if !did_filetype() && empty(win_gettype())
	\    && expand("<amatch>:e") =~ '\w'
	\|   exe 'setf ' .. expand("<amatch>:e")
	\| endif
